//package com.asset.crm.dao;
//
//
//import java.text.DateFormat;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Iterator;
//import java.util.List;
//
//import org.hibernate.Query;
//import org.hibernate.Session;
//import org.hibernate.SessionFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Repository;
//import org.springframework.transaction.annotation.Transactional;
//
//import com.asset.crm.domain.Contact;
//import com.asset.crm.domain.Employee;
//import com.asset.crm.domain.Lead;
//import com.asset.crm.domain.Login;
//
//
//@Repository
//public class LeadDaoImpl {
//	@Autowired
//	SessionFactory sessionFactory;
//	@SuppressWarnings("unchecked")
//	public List<Lead> getAllLead(Integer index,Integer companyId,Integer count) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Lead  where isDeleted= :isDeleted and isConverted=:isConverted and leadOwner.company.id = :companyId ");
//		query.setParameter("isDeleted", false);
//		query.setParameter("isConverted", false);
//		query.setParameter("companyId", companyId);
//		query.setFirstResult((index*count));
//		query.setMaxResults(count);
//		List<Lead> leads;
//		leads = query.list();
//		return  leads;
//	}
//	@SuppressWarnings("unchecked")
//	public Integer getAllLeadSize(Integer companyId) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Lead where isDeleted= :isDeleted And leadOwner.company.id = :companyId");
//		query.setParameter("isDeleted", false);
//		query.setParameter("companyId", companyId);
//		List<Lead> leads= new ArrayList<Lead>();
//		leads = query.list();
//		if(leads != null && leads.size() > 0){
//		return  leads.size();
//		}
//		else{return null;}
//	}
//
//	public Lead addLead(Lead lead) {
//		try{
//		sessionFactory.getCurrentSession().save(lead);
//		}catch(Exception ex){
//			ex.printStackTrace();
//		}
//		return lead;
//	}
//	public List<Lead> getLead(Integer leadOwnerId){
//		Session session = sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Lead where  leadOwner.id = :leadOwnerId");
//		query.setParameter("leadOwnerId", leadOwnerId);
//		@SuppressWarnings("unchecked")
//		List<Lead>  leads= query.list();
//		if(leads != null && leads.size() > 0)
//		return leads;
//		else
//			return new ArrayList<Lead>();
//		
//	}
//	
//	public Lead getLeadByEmpId(Integer empId){
//		Session session = sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Lead where  leadOwner.id = :empId");
//		query.setParameter("empId", empId);
//		@SuppressWarnings("unchecked")
//		List<Lead>  leads= query.list();
//		System.out.println("><><><><><><+++++++++++++++++++++++++++++"+leads.size());
//		if(leads.size() > 0)
//		return leads.get(0);
//		else
//			return null;
//		
//	}
//	
//	public Lead getLeadById(Integer Id){
//		Session session = sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Lead where  id = :Id");
//		query.setParameter("Id", Id);
//		@SuppressWarnings("unchecked")
//		List<Lead>  leads= query.list();
//		System.out.println("><><><><><><+++++++++++++++++++++++++++++"+leads.size());
//		if(leads.size() > 0)
//		return leads.get(0);
//		else
//			return null;
//		
//	}
//
//	public void saveOrupdate(Lead lead){
//		Session session = sessionFactory.getCurrentSession();
//		session.saveOrUpdate(lead);
//	}
//	
//	public Lead loadLead(Integer id) {
//		Lead lead = (Lead)sessionFactory.getCurrentSession().get(Lead.class, id);
//		return lead;
//		
//	}
//	
//	public void deleteLead(Lead lead) {
//		sessionFactory.getCurrentSession().delete(lead);
//		
//	}	
//	
//	public List<String> getViewLeads(List<String> fields, List<String> cols, List<String> operators, List<String> values, String  fromDomain, String reportPeriod){
//		Session session = sessionFactory.getCurrentSession();
//		String queryStatement = "select ";
//		Integer i=0;
//		System.out.println("?????????????????????? fromDomain ???????  " + fromDomain);
//		for (String field : fields) {
//			if(field == fields.get(fields.size() -1))
//				queryStatement += field + " from " + fromDomain + " where (";
//			else
//				queryStatement += field + ", ";
//		}
//
//		for (String col : cols) {
//			
//			if(i<cols.size() - 1)
//				queryStatement +=  col + " " + operators.get(i) + " '" + values.get(i) + "' OR ";
//			else
//				queryStatement +=  col + " " + operators.get(i) + " '" + values.get(i) + "')";
//			i++;
//		}
//		if(reportPeriod == null || reportPeriod.equalsIgnoreCase("")){
//			System.out.println("nuuuuuuuuuuuuuuuuuuuuuuul period");
//		}
//		else{
//			java.util.Date startDate = new java.util.Date();
//			java.util.Date endDate = new java.util.Date();
//			DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
//			java.util.Date date1 = new java.util.Date();
//			Calendar endCalendar;
//			endCalendar = Calendar.getInstance();
//			endCalendar.setTime(date1);
//			Calendar startCalendar = Calendar.getInstance();
//			startCalendar.setTime(date1);
//				if(reportPeriod=="daily" || reportPeriod.equalsIgnoreCase("daily")){
//					startCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.get(Calendar.DAY_OF_MONTH)-1);
//					int daily = startCalendar.get(Calendar.DAY_OF_MONTH);
//					System.out.println("success"+daily);
//				}
//				else if(reportPeriod == "weekly" || reportPeriod.equalsIgnoreCase("weekly")){
//					startCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.get(Calendar.DAY_OF_MONTH)-7);
//					int weekly = startCalendar.get(Calendar.DAY_OF_MONTH);
//					System.out.println("success"+weekly);
//				}
//				else if(reportPeriod=="monthly" || reportPeriod.equalsIgnoreCase("monthly")){
//					startCalendar.set(Calendar.MONTH, endCalendar.get(Calendar.MONTH)-1);
//					int monthly = startCalendar.get(Calendar.MONTH);
//					System.out.println("success"+monthly);
//				}
//				else if(reportPeriod=="yearly" || reportPeriod.equalsIgnoreCase("yearly")){
//					startCalendar.set(Calendar.YEAR, endCalendar.get(Calendar.YEAR)-1);
//					int yearly = startCalendar.get(Calendar.YEAR);
//					System.out.println("success"+yearly);
//				}
//				else{
//					System.out.println("!!!!!!!!!!!!!!!! " + reportPeriod + " !!!!!!!!!!!!!");
//				}
//			startDate = startCalendar.getTime();
//			String startDateStr = dateFormat.format(startDate);
//			endDate = endCalendar.getTime();
//			String endDateStr = dateFormat.format(endDate);
//			queryStatement += " and dateCreated between '" + startDateStr + "' and '" + endDateStr + "'";
//			System.out.println("!!!!!!!!!!!!!!!! " + reportPeriod + " !!!!!!!!!!!!!" + startDateStr + "###" + endDateStr);
//		}
//		//queryStatement += "and ( leadOwner.id )";//queryStatement = "from Lead as Lead where Lead.id = 1";
////		String createdDate = "select t.dateCreated form " + fromDomain + " t";
////		String modifiedDate = "select t.dateModified form " + fromDomain + " t";
////		Query createdDateQuery = session.createQuery(createdDate);
////		Query modifiedDateQuery = session.createQuery(modifiedDate);
//		//queryStatement = "select Lead.leadOwner.company.employeesNumber, Lead.lName from Lead as Lead where Lead.id = 1";
//		System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + queryStatement + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//		
//		Query query = session.createQuery(queryStatement);
////		query.setParameter("startDate", startDate);
////		query.setParameter("endDate", endDate);
//		List<String> l =query.list();
//        System.out.println("Total Number Of Records : "+l.size());
//        @SuppressWarnings("rawtypes")
//		Iterator it = l.iterator();
//        
//        while(it.hasNext())
//        {
//            Object o[] = (Object[])it.next();
//            System.out.println("Product id : "+o[0]+ "Product Name : "+o[1]);
//            System.out.println("----------------");
//        }
//		return l;
//	}
//	public List<String> getViewCustomDate(List<String> fields, List<String> cols, List<String> operators, List<String> values, String fromDomain, String startD, String endD) {
//		Session session = sessionFactory.getCurrentSession();
//		String queryStatement = "select ";
//		Integer i=0;
//		System.out.println("?????????????????????? fromDomain ???????  " + fromDomain);
//		for (String field : fields) {
//			if(field == fields.get(fields.size() -1))
//				queryStatement += field + " from " + fromDomain + " where (";
//			else
//				queryStatement += field + ", ";
//		}
//
//		for (String col : cols) {
//			
//			if(i<cols.size() - 1)
//				queryStatement +=  col + " " + operators.get(i) + " '" + values.get(i) + "' OR ";
//			else
//				queryStatement +=  col + " " + operators.get(i) + " '" + values.get(i) + "')";
//			i++;
//		}
//		if(startD == null || startD.equalsIgnoreCase("")){
//			System.out.println("nuuuuuuuuuuuuuuuuuuuuuuul start date...");
//		}
//		else{
//			java.util.Date startDate = new java.util.Date(startD);
//			java.util.Date endDate = new java.util.Date(endD);
//			DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
//			java.util.Date date1 = new java.util.Date();
//			Calendar endCalendar;
//			endCalendar = Calendar.getInstance();
//			endCalendar.setTime(endDate);
//			Calendar startCalendar = Calendar.getInstance();
//			startCalendar.setTime(startDate);
////				if(reportPeriod=="daily" || reportPeriod.equalsIgnoreCase("daily")){
////					startCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.get(Calendar.DAY_OF_MONTH)-1);
////					int daily = startCalendar.get(Calendar.DAY_OF_MONTH);
////					System.out.println("success"+daily);
////				}
//			startDate = startCalendar.getTime();
//			String startDateStr = dateFormat.format(startDate);
//			endDate = endCalendar.getTime();
//			String endDateStr = dateFormat.format(endDate);
//			queryStatement += " and dateCreated between '" + startDateStr + "' and '" + endDateStr + "'";
//			System.out.println( startD + "!!!!!!!!!!!!!!!! " + startDate + " !!!!!!!!!!!!!" + startDateStr + "###" + endDateStr);
//		}
//		System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + queryStatement + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//		
//		Query query = session.createQuery(queryStatement);
////		query.setParameter("startDate", startDate);
////		query.setParameter("endDate", endDate);
//		List<String> l =query.list();
//        System.out.println("Total Number Of Records : "+l.size());
//        @SuppressWarnings("rawtypes")
//		Iterator it = l.iterator();
//        while(it.hasNext())
//        {
//            Object o[] = (Object[])it.next();
//            System.out.println("Product id : "+o[0]+ "Product Name : "+o[1]);
//            System.out.println("----------------");
//        }
//		return l;
//	}
//
//}
